<!DOCTYPE html>
<html>
  
  <head>
    <meta charset="UTF-8">
    <title>商品评论列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="./css/font.css">
    <link rel="stylesheet" href="./css/xadmin.css">
    <link rel="stylesheet" href="./css/inputC.css">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript" src="./lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="./js/xadmin.js"></script>
    <!-- 引入layui.css -->
    <link rel="stylesheet" href="https://www.layuicdn.com/layui-v2.5.6/css/layui.css">
    <!-- 引入layui.js -->
    <script scr="https://www.layuicdn.com/layui-v2.5.6/layui.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
      <link rel="stylesheet" href="./css/welcome.css">
  </head>
  
  <body>
    <div class="x-nav">
      <span class="layui-breadcrumb">
      </span>
      <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
    </div>
  <!--  <div class="x-body">
      &lt;!&ndash;表单信息（搜索条件）&ndash;&gt;
        <div class="father">
            <div class="searchBox layui-form">
                <div class="itemDate">
                    <input type="radio" name="date" value="0" title="累计" lay-filter="radio-filter" >
                </div>
                <div class="itemDate">
                    <input type="radio" name="date" value="1" title="今日" checked lay-filter="radio-filter">
                </div>
                <div class="itemDate">
                    <input type="radio" name="date" value="2" title="昨日" lay-filter="radio-filter">
                </div>
                <div class="itemDate">
                    <input type="radio" name="date" value="3" title="本月" lay-filter="radio-filter">
                </div>
                <div class="itemDate">
                    <input type="radio" name="date" value="4" title="上月" lay-filter="radio-filter">
                </div>
                <div class="itemDate">
                    <input type="radio" name="date" value="5" title="最近三月" lay-filter="radio-filter">
                </div>
                <div class="itemDate">
                    <input type="radio" name="date" value="6" title="今年" lay-filter="radio-filter">
                </div>
                <div class="itemDate">
                    <input type="radio" name="date" value="7" title="去年" lay-filter="radio-filter">
                </div>
                <div class="itemDate">
                    <input type="radio" name="date" value="8" title="自定义时间段" lay-filter="radio-filter" disabled>
                </div>
                <div class="itemDate">
                    <input  type="text" class="layui-input" name="dateRange"  id="dateSelect" placeholder="查询日期">
                </div>
                <div class="itemDate">
                    <button class="layui-btn" lay-submit lay-filter="searchReview">查询</button>
                </div>
            </div>
        </div>
      </div>-->
<!--              <xblock>-->
<!--                <button class="layui-btn layui-btn-normal" onclick="x_admin_show('添加优惠券','./coupon-add.html',1200,600)" id="addCoupon"><i class="layui-icon layui-icon-add-1"></i>新增优惠券</button>-->
<!--              </xblock>-->
      <script type="text/html" id="table-operation">
        <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="reply">回复评论</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除评论</a>
        {{# if(d.state == 0) { }}
        <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="hidden">隐藏评论</a>
        {{# } else { }}
        <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="display">显示评论</a>
        {{# } }}
      </script>

    <script type="text/html" id="ratingTemp">
     {{d.rating}}<i class="layui-icon" style="font-size: 15px; color: #FF5722;">&#xe67a;</i>
    </script>

      <div style="text-align: center">
        <!--数据表格位置-->
        <table id="data-table" lay-filter="data-table"></table>
        <!--分页位置-->
        <div id="data-page" class="layui-table-page" lay-filter="data-page"></div>
      </div>

    </div>


    <script>

      layui.use(['form','table','laypage','layer','laydate'], function() {
        var $ = layui.jquery
                ,form = layui.form,table = layui.table,laypage=layui.laypage,layer=layui.layer,laydate=layui.laydate;

        var limits = [10, 20, 30, 40]

    let couponTable=table.render({
          elem: "#data-table",
          url: "/review/getAllReview",//请求地址
          // page: true, //开启分页
          id:"idTest",
          cols: [[
              {field: "rid",  title: "ID",width: 80,hide:true},
              {field: "uid",  title: "ID",hide:true},
              {field: "gid",  title: "ID",hide:true},
              {field: "goodstitle", title: "商品名称",align: "center"},
              {field: "reviewtime", title: "评论时间",sort:true, align: "center",width: 190},
              {field: "username", title: "用户名称",align: "center",width: 150},
              {field: "rating", title: "评级(星)",align: "center",width: 100,templet: "#ratingTemp"},
              {field: "couponstate", title: "评论状态",align: "center",templet: "#reviewStateTemp",width: 150},
              {field: "content", title: "评级内容",align: "center",width: 150},
              {field: "reply", title: "回复内容",align: "center",width: 150},
              {title: "操作", align: "center",toolbar: "#table-operation",width:240,}
            ]],
          done:function (res, curr, count) {
              console.log("coupon数据------------>")
              console.log(res)
            laypage.render({
                  elem: 'data-page',//被渲染的分页栏id，此处不需要加#号
                  count: count,//数据总条数
                  curr:  res.pageNum,//当前页码
                  limit: res.pageSize,//当前页展示的最大行数
                  limits: limits,//分页大小选项
                  layout:['count','prev','page','next','limit','skip'],
                  jump:function (obj,first) {
                    console.log("当前分页栏的属性")
                    console.log(obj)
                    if (!first){
                      table.reload('idTest', {
                        where: {
                          "pageNum":obj.curr,
                          "pageSize":obj.limit
                        }
                      });
                    }
                  }
            });
          },
        });



        /*
        * 右侧工具类编辑、删除、查看等的点击事件函数
        * */
          table.on('tool(data-table)', function(obj) { //注：tool 是工具条事件名，data-table 是 table 原始容器的属性 lay-filter="对应的值"
              var data = obj.data; //获得当前行数据
              var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
              var tr = obj.tr; //获得当前行 tr 的 DOM 对象（如果有的话）
              console.log(data)
              var rid = data.rid;
              if (layEvent === 'reply') { //回复评论
                  layer.open({
                      type: 2,
                      area: [600+'px', 400 +'px'],
                      fix: false, //不固定
                      maxmin: true,
                      shadeClose: true,
                      shade:0.4,
                      title: '回复评论',
                      content: './reply.html',
                      success: function (layero, index) {
                        var body = layer.getChildFrame('body', index);
                        body.find("#rid").val(rid);
                        body.find("#reply").val(data.reply);
                      },
                    end: function(index, layero){
                      couponTable.reload();
                    }
                  })
                      couponTable.reload()
              } else if (layEvent === 'del') { //删除
                  layer.confirm('真的删除行么', function (index) {
                      $.ajax({
                          type: 'GET',
                          url: '/review/delReview/'+rid,
                          processData: false,
                          contentType: false,
                          async: false,
                          success: function (res) {
                            obj.del(); //删除对应行（tr）的DOM结构，并更新缓存
                            layer.msg('删除成功', {icon: 1});
                          }
                      });
                  });
              } else if (layEvent === 'display') { //显示评论-state改为0
                  $.ajax({
                      type: 'GET',
                      url: '/review/updateReviewState/'+data.rid+"/"+0,
                      processData: false,
                      contentType: false,
                      async: false,
                      success: function (res) {
                          console.log(res);
                          couponTable.reload()
                      }
                  })
              } else if (layEvent === 'hidden') { //隐藏评论-state改为1
                  $.ajax({
                      type: 'GET',
                      url: '/review/updateReviewState/'+data.rid+"/"+1,
                      processData: false,
                      contentType: false,
                      async: false,
                      success: function (res) {
                          console.log(res);
                          couponTable.reload()
                      }
                  })
              }
      })
      })
      //layui结束

    </script>
    <script type="text/html" id="imgtmp">
        <img src="{{d.couponimg}}" style="width:80px;height: 50px;">
    </script>
    <script type="text/html" id="statusTemplet">
      {{# if(d.memberstate == 0) { }}
      <button class="layui-btn layui-btn layui-btn-xs">普通用户</button>
      {{# } else { }}
      <button class="layui-btn layui-btn-warm layui-btn-xs">会员用户</button>
      {{# } }}
    </script>
    <script type="text/html" id="reviewStateTemp">
        {{# if(d.state == 0) { }}
        <button class="layui-btn layui-btn-normal layui-btn-xs">已显示</button>
        {{# } else { }}
        <button class="layui-btn layui-btn-warm layui-btn-xs">已隐藏</button>
        {{# } }}
    </script>
  </body>

</html>